package com.eric.text;

import java.util.List;

import org.ansj.app.summary.SummaryComputer;
import org.ansj.app.summary.pojo.Summary;
import org.ansj.domain.Result;
import org.ansj.domain.Term;
import org.ansj.library.UserDefineLibrary;
import org.ansj.splitWord.analysis.ToAnalysis;
import org.apache.commons.lang3.StringUtils;
import org.jsoup.nodes.Document;

public class AnsjTaggerWorker extends AbstractTextWorker {

	private int sumNum = 100;

	public AnsjTaggerWorker(Object input) {
		super(input);
	}

	@Override
	public void produce() {
		init();
		initThis();

		Result r = ToAnalysis.parse(text);
		for (Term t : r) {
			if (StringUtils.isNotBlank(t.getName()) && !t.getName().matches("^[,.¥￥。、\"”&@#$*|]$"))
				result.add(t.getName() + "/" + t.natrue());
		}

		SummaryComputer summaryComputer = new SummaryComputer(sumNum, doc.title(), text);
		Summary sum = summaryComputer.toSummary();
		result.add(sum.getSummary());
	}

	@Override
	protected void initThis() {
		if (customWords.size() > 0) {
			for (String s : customWords) {
				UserDefineLibrary.insertWord(s);
			}
		}

	}

	@Override
	public List<String> getContext() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<String> produce(String text, Document doc) {
		// TODO Auto-generated method stub
		return null;
	}

}
